package utils

import (
	"context"
	"server/global"
	"time"
)

type RedisUtils struct{}

/**·
 * @description: 设置缓存
 * @param {context.Context} ctx
 * @param {string} key
 * @param {interface{}} value
 * @param {time.Duration} expiration
 * @return {*}
 */
func (r *RedisUtils) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error {
	return global.GA_REDIS_CLIENT.Set(ctx, key, value, expiration).Err()
}

/**
 * @description: 获取缓存
 * @param {context.Context} ctx
 * @param {string} key
 * @return {*}
 */
func (r *RedisUtils) Get(ctx context.Context, key string) (string, error) {
	return global.GA_REDIS_CLIENT.Get(ctx, key).Result()
}

/**
 * @description: 删除缓存
 * @param {context.Context} ctx
 * @param {string} key
 * @return {*}
 */
func (r *RedisUtils) Delete(ctx context.Context, key string) error {
	return global.GA_REDIS_CLIENT.Del(ctx, key).Err()
}
